% Demonstration of pgf-umlsd.sty, a set of convenient macros for drawing
% UML sequence diagrams. Written by Xu Yuan <xuyuan.cn AT gmail.com> from
% Southeast University, China.
% The project is hosted at Google code: http://code.google.com/p/pgf-umlsd/ 
\documentclass{article}

\usepackage{tikz}
\usepackage{pgf-umlsd}
\usepgflibrary{arrows} % for pgf-umlsd
\usepackage{verbatim}

\begin{comment}
:Title: UML sequence diagrams
:Slug: pgf-umlsd
:Tags: Macro packages
:Use page: 2

Demonstration of `pgf-umlsd.sty`_, a set of convenient macros for drawing UML sequence diagrams.

To compile the example you will need the following style file:

- `pgf-umlsd.sty`_

The macros are documented in the style file.

**Update**: pgf-umlsd is now `hosted at Google code`_. 

.. _pgf-umlsd.sty: http://pgf-umlsd.googlecode.com/svn/trunk/pgf-umlsd.sty
.. _hosted at Google code: http://code.google.com/p/pgf-umlsd/

:Author: Xu Yuan, Southeast University, China

\end{comment}

\begin{document}

\begin{figure}
  \centering

  \begin{sequencediagram}
    \newthread{ss}{}{SimulationServer}
    \newinst{ctr}{}{SimControlNode}
    \newinst{ps}{}{PhysicsServer}
    \newinst[1]{sense}{}{SenseServer}

    \begin{call}{ss}{Initialize()}{sense}{}
    \end{call}
    \begin{sdloop}{Run Loop}
      \begin{call}{ss}{StartCycle()}{ctr}{}
        \begin{call}{ctr}{ActAgent()}{sense}{}
        \end{call}
      \end{call}
      \begin{call}{ss}{Update()}{ps}{}
        \begin{call}{ps}{PrePhysicsUpdate()}{sense}{state}
        \end{call}
        \begin{callself}{ps}{PhysicsUpdate()}{}
        \end{callself}
        \begin{call}{ps}{PostPhysicsUpdate()}{sense}{}
        \end{call}
      \end{call}
      \begin{call}{ss}{EndCycle()}{ctr}{}
        \begin{call}{ctr}{SenseAgent()}{sense}{}
        \end{call}
      \end{call}
    \end{sdloop}
  \end{sequencediagram}

  \caption{UML sequence diagram demo.}
\end{figure}

\begin{figure}
  \centering

  \begin{sequencediagram}
    \newthread{ss}{}{SimulationServer}
    \newinst{ps}{}{PhysicsServer}
    \newinst[1]{sense}{}{SenseServer}
    \newthread[red]{ctr}{}{SimControlNode}

    \begin{sdloop}[green!20]{Run Loop}
      \mess{ctr}{StartCycle}{ss}
      \begin{call}{ss}{Update()}{ps}{}
        \prelevel
        \begin{callself}{ctr}{SenseAgent()}{}
          \begin{call}[3]{ctr}{Read}{sense}{}
          \end{call}
        \end{callself}
        \prelevel\prelevel\prelevel\prelevel
        \setthreadbias{west}
        \begin{call}{ps}{PrePhysicsUpdate()}{sense}{}
        \end{call}
        \setthreadbias{center}
        \begin{callself}{ps}{Update()}{}
        \end{callself}
        \begin{call}{ps}{PostPhysicsUpdate()}{sense}{}
        \end{call}
      \end{call}
      \mess{ss}{EndCycle}{ctr}
      \begin{callself}{ctr}{ActAgent()}{}
        \begin{call}{ctr}{Write}{sense}{}
        \end{call}
      \end{callself}
    \end{sdloop}

  \end{sequencediagram}

  \caption{Example of a sequence with parallel activities.}
\end{figure}

\end{document}

